DatePart returns a Number that specifies a given part of a given date.
The following examples are applicable to both Basic and Crystal syntax:
DatePart ("d", #August 15, 1999#)
DatePart ("m", #August 15, 1999#)
DatePart ("q", #September 29, 1999#)
Returns 3 since September 29 is in the third quarter of the year.
DatePart ("ww", #September 14, 1997#)
Returns 38 since September 14, 1997 is in the 38th week of 1997.
Suppose that a company wants to stamp an id number on each of its shipments for quality control purposes. The id is composed of the order id, followed by a dash, followed by the week the order was shipped, followed by the last two digits of the year. Here is an example formula that produces these ids:
formula = CStr({Orders.Order ID}, 0, "") & "-" & _
CStr(DatePart("ww", {Orders.Ship Date}), 0) & _
CStr({Orders.Ship Date}, "yy")
CStr({Orders.Order ID}, 0, "") & "-" &
CStr(DatePart("ww", {Orders.Ship Date}), 0) &
CStr({Orders.Ship Date}, "yy")
Returns the string "2082
This function is designed to work like the Visual Basic function of the same name.
The DatePart function with "yyyy" intervalType argument is the same as the Year function. Similarly, the DatePart function with "m", "d", "w", "h", "n" and "s" intervalType argument is the same as the functions Month, Day, Weekday (or DayOfWeek), Hour, Minute and Second respectively. On the other hand, there is no easy alternative to using the DatePart function for the "q", "y" and "ww" intervalType arguments.
The firstDayOfWeek argument affects the DatePart function when the interval type argument is "w" or "ww". For all other intervalType argument values, it is ignored.
The firstWeekOfYear argument affects the DatePart function only when the intervalType argument is "ww". For all other intervalType argument values, it is ignored.
Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |